<%--
  Created by IntelliJ IDEA.
  User: 23377
  Date: 2021/12/12
  Time: 20:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix ="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
    <title>书籍展示</title>
    <%
        pageContext.setAttribute("APP_PATH",request.getContextPath());
    %>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="${APP_PATH}/static/bootstrap-3.4.1-dist/bootstrap-3.4.1-dist/css/bootstrap.min.css" rel="stylesheet" />
    <script type="text/javascript" src="${APP_PATH}/static/js/jQuert-min-3.js"></script>
    <script type="text/javascript" src="${APP_PATH}/static/bootstrap-3.4.1-dist/bootstrap-3.4.1-dist/js/bootstrap.min.js"></script>

</head>
<body>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="page-header">
                <h1>
                    <small>书籍列表</small>
                </h1>
            </div>
        </div>
    </div>
    <div class="row clearfix">
        <div class="col-md-4 column">
            <a class="btn btn-primary" href="${pageContext.request.contextPath}/book/toAddBook">新增书籍</a>
            <a class="btn btn-primary" href="${pageContext.request.contextPath}/book/allBook">显示全部书籍</a>
        </div>
        <div class="col-md-4 column"></div>
        <div class="col-md-4 column">
            <form class="form-inline" action="${pageContext.request.contextPath}/book/queryBook" method="post"
                  style="float: right">
            <span style="color:red;font-weight: bold">${error}
            </span>
                <label>
                    <input type="text" name="queryBookName" class="form-control"
                           placeholder="输入要查询书名" required/>
                </label>
                <input type="submit" value="查询" class="btn btn-info">
            </form>
        </div>

    </div>

    <div class="row clearfix">
        <div class="col-md-12 column">
            <table class="table table-hover table-striped">
                <thead>
                <tr>
                    <th>书籍编号</th>
                    <th>书籍名字</th>
                    <th>书籍数量</th>
                    <th>书籍详情</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
<%--                    书籍从数据库中查出来，从model的属性list中获取遍历出来进行展示--%>
                <c:forEach var="books" items="${list}">
                    <tr>
                        <td>${books.bookId}</td>
                        <td>${books.bookName}</td>
                        <td>${books.bookCount}</td>
                        <td>${books.detail}</td>
                        <td>
                            <a href="${pageContext.request.contextPath}/book/toUpdateBook?id=${books.bookId}" class="btn btn-success">
                                更改</a> |
                            <a href="${pageContext.request.contextPath}/book/deleteBook/${books.bookId}" class="btn btn-danger">
                                删除</a>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
        </div>
    </div>


<%--    显示分页信息--%>
    <div class="row">
<%--    分页文字信息--%>
        <div class="col-md-6">
            当前【${pageInfo.pageNum}】页,总【${pageInfo.pages}】页,总【${pageInfo.total}】条记录
        </div>
<%--        分页条信息--%>
        <div class="col-md-6">
            <nav aria-label="Page navigation">
                <ul class="pagination">
<%--                    首页--%>
                    <li><a href="${pageContext.request.contextPath}/book/allBooks?pn=1">首页</a> </li>
<%--                    前一页--%>
                    <c:if test="${pageInfo.hasPreviousPage}">
                        <li><a href="${pageContext.request.contextPath}/book/allBooks?pn=${pageInfo.pageNum-1}"
                        aria-label="Previous"><span aria-hidden="true">&laquo;</span> </a> </li>
                    </c:if>
<%--                    显示中间页码--%>
                    <c:forEach items="${pageInfo.navigatepageNums}" var="page_num">
                        <c:if test="${page_num==pageInfo.pageNum}">
                            <li class="active"><a href="#">${page_num}</a> </li>
                        </c:if>
                        <c:if test="${page_num!=pageInfo.pageNum}">
                            <li><a href="${pageContext.request.contextPath}/book/allBooks?pn=${page_num}">${page_num}</a> </li>
                        </c:if>
                    </c:forEach>
<%--                    后一页--%>
                    <c:if test="${pageInfo.hasNextPage}">
                        <li><a href="${pageContext.request.contextPath}/book/allBooks?pn=${pageInfo.pageNum+1}"
                        aria-label="Next"><span aria-hidden="true">&raquo;</span>
                        </a> </li>
                    </c:if>
<%--                    末页--%>
                    <li><a href="${pageContext.request.contextPath}/book/allBooks?pn=${pageInfo.pages}">末页</a> </li>
                </ul>
            </nav>
        </div>
    </div>
</div>
</body>
</html>
